package com.isunland.managesystem.ui;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
import com.android.volley.VolleyError;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.isunland.managesystem.R;
import com.isunland.managesystem.base.BaseSingleButtonDialogFragment;
import com.isunland.managesystem.base.BaseVolleyActivity;
import com.isunland.managesystem.common.ApiConst;
import com.isunland.managesystem.common.VolleyResponse;
import com.isunland.managesystem.entity.CertificateNoContent;
import com.isunland.managesystem.entity.CurrentUser;
import com.isunland.managesystem.entity.DataStatus;
import com.isunland.managesystem.entity.DeleteSuccessMessage;
import com.isunland.managesystem.entity.EmployeeLoanContent;
import com.isunland.managesystem.entity.SuccessMessage;
import com.isunland.managesystem.utils.FileNetWorkUtil;
import com.isunland.managesystem.utils.LogUtil;
import com.isunland.managesystem.utils.MyUtils;
import com.loopj.android.http.AsyncHttpResponseHandler;
import java.util.HashMap;
import java.util.UUID;
import org.apache.http.Header;
import org.json.JSONException;

/**
 * Created by lenovo on 2016/6/2.
 */
public class EditeManageReimburseFragment extends ManagelReimburseFragment {
  public static final String EXTRA_TRAVELREIMBURSE_CONTENT =
      "com.isunland.managesystem.ui.EXTRA_EXTRA_TRAVELREIMBURSE_CONTENT";
  private static final int REQUEST_CONTRACT = 0;
  public static final String EXTRA_CODE = "com.isunland.managesystem.ui.EXTRA_CODE";
  private EmployeeLoanContent mContent;
  private CurrentUser mCurrentUser;
  private StringBuilder mManageCode = new StringBuilder();
  private String code;
  private String fileName = "";// 会员编码
  private Double replenishAmount = 0.0;//本次预存票据

  @Override protected void setTitle() {

    //        mManageCode.append(mCurrentUser.getMemberCode()).append("-").append("DJLB-CWZC-GLFYBX");
    //
    //        if (mManageCode.toString().equals(code)) {
    //            ( (BaseVolleyActivity) getActivity()).getSupportActionBar().setTitle(R.string.manageReimburse);
    //        } else {
    //            ( (BaseVolleyActivity) getActivity()).getSupportActionBar().setTitle(R.string.travelReimburse1);
    //        }
    ((BaseVolleyActivity) getActivity()).getSupportActionBar().setTitle(R.string.manageReimburse);
  }

  @Override public void onCreate(Bundle savedInstanceState) {
    mContent = (EmployeeLoanContent) getArguments().getSerializable(EXTRA_TRAVELREIMBURSE_CONTENT);
    mCurrentUser = CurrentUser.newInstance(getActivity());
    if (mContent != null) {
      code = mContent.getCertificateCode();
    }
    fileName = mContent.getFileOriginalName();
    mfileName = fileName;
    selcurFile = mContent.getFilePath();

    super.onCreate(savedInstanceState);
  }

  // 创建菜单
  @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_confirm, menu);
    super.onCreateOptionsMenu(menu, inflater);
  }

  @Override protected void initData() {
    //只有草稿状态获取已有借款合计
    if ((mContent.getDataStatus()).equals(DataStatus.NEW)) {
      tvsumBorrow.setText(mContent.getSumBorrow());
      getSumBorrow();//获取已有借款合计
    } else {
      tvsumBorrow.setText(mContent.getSumBorrow());
    }
    tvcertificateNo.setText(mContent.getCertificateNo());
    tvregStaffName.setText(mCurrentUser.getRealName());
    tvapplicantName.setText(mCurrentUser.getRealName());
    tvapplyTime.setText(mContent.getApplyTime());
    //合同
    if (!TextUtils.isEmpty(mContent.getContractProjectName())) {
      tvcontractId.setText(mContent.getContractProjectName());
    }
    if (!TextUtils.isEmpty(mContent.getOrderName())) {
      tvcontractId.setText(mContent.getOrderName());
    }
    if (!TextUtils.isEmpty(mContent.getContractName())) {
      tvcontractId.setText(mContent.getContractName());
    }
    etexpenseDesc.setText(mContent.getExpenseDesc());
    etpoutAmount.setText(mContent.getToutAmount());
    etoffBorrow.setText(mContent.getOffBorrow());// 冲抵金额
    ettoutAmount.setText(mContent.getPoutAmount());

    tag = mContent.getIfOffBorrow();
    if ("T".equals(tag)) {
      rbtrueOffset.setChecked(true);
      rbfalseOffset.setChecked(false);
    } else {
      rbfalseOffset.setChecked(true);
      rbtrueOffset.setChecked(false);
    }
    //票据
    //		tvsumPrebill.setText(mContent.getSumPrebill());//合计预存票据
    //		etbillAmount.setText(mContent.getBillAmount());
    //		etnobillAmount.setText(mContent.getNobillAmount());
    //		tvreplenishAmount.setText(mContent.getReplenishAmount());//合计预存票据

    //        etbillAmount.setText(mContent.getBillAmount());
    //        etdeductionAmount.setText(mContent.getDeductionAmount());
    etpayeeBank.setText(mContent.getPayeeBank());
    etpayeeAccname.setText(mContent.getPayeeAccname());
    etpayeeAccount.setText(mContent.getPayeeAccount());

    fownerkindName = mContent.getFownerkindName();
    fownerkindCode = mContent.getFownerkindCode();
    appobjectName = mContent.getAppobjectName();
    appobjectCode = mContent.getAppobjectId();
    tvfownerkindName.setText(mContent.getFownerkindName());//归属分类
    tvappobjectName.setText(mContent.getAppobjectName());//归属对象
    // 初始化合同id.
    mContractId = mContent.getContractId();
    mContractName = mContent.getContractName();
    mContractKind = mContent.getContractKind();
    mContractCode = mContent.getContractCode();
    mOrderId = mContent.getOrderId();
    mOrderName = mContent.getOrderName();
    mOrderType = mContent.getOrderType();
    mProjectId = mContent.getContractProjectId();
    mProjectName = mContent.getContractProjectName();
    mContractPrice = mContent.getContractAmount();

    //		ibcontract.setOnClickListener(new OnClickListener() {
    //			@Override
    //			public void onClick(View arg0) {

    //				Bundle bundle = new Bundle();
    //				bundle.putSerializable(EXTRA_CODE, code);
    //
    //				DialogFragment dialog = null;
    //				dialog = new ContractDialogFragment();
    //				FragmentManager fm = getActivity().getSupportFragmentManager();
    //				dialog.setTargetFragment(EditeTravelReimburseFragment.this, REQUEST_CONTRACT);
    //				dialog.setArguments(bundle);
    //				dialog.show(fm, "");
    //				Intent i=new Intent(getActivity(),ContractChoosePagerActivity.class);
    //				i.putExtra(EXTRA_CODE,code);
    //				startActivityForResult(i,REQUEST_CONTRACT);
    //			}
    //		});
    if (!TextUtils.isEmpty(mContent.getFileOriginalName())) {
      //附件
      mTvExtra.setText(mContent.getFileOriginalName());
      //点击附件名，下载附件
      mTvExtra.setOnClickListener(new View.OnClickListener() {

        @Override public void onClick(View v) {
          ExtraDownLoadDialogFragment dialog = null;
          if (TextUtils.isEmpty(mFilePath)) {
            dialog = ExtraDownLoadDialogFragment.newInstance("", selcurFile);
          } else {
            dialog = ExtraDownLoadDialogFragment.newInstance(mFilePath, "");
          }

          FragmentManager fm = getActivity().getSupportFragmentManager();
          dialog.show(fm, "");
        }
      });
    }
  }

  public void getSumBorrow() {
    String url = ApiConst.getAbsoluteUrl(ApiConst.URL_ADD_EMPLOYEE_LOAN_DETAIL);
    HashMap<String, String> params = new HashMap<String, String>();
    params.put("certificateCode", mContent.getCertificateCode());
    params.put("userJobNo", mCurrentUser.getJobNumber());
    MyUtils.showDialogLoading(getActivity());
    mActivity.volleyPost(url, params, new VolleyResponse() {

      @Override public void onVolleyResponse(String arg0) throws JSONException {
        MyUtils.dismissDialog();
        CertificateNoContent[] array = new Gson().fromJson(arg0, CertificateNoContent[].class);
        CertificateNoContent mNoContent = array[0];
        tvsumBorrow.setText(mNoContent.getSumBorrow());//已有借款合计
      }

      @Override public void onVolleyError(VolleyError arg0) {
        // Auto-generated method stub
      }
    });
  }

  // 菜单相应事件
  @Override public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case android.R.id.home:
        //			if (NavUtils.getParentActivityName(getActivity()) != null) {
        //				NavUtils.navigateUpFromSameTask(getActivity());
        //			}
        getActivity().finish();
        return true;
      // 保存
      case R.id.menu_item_confirm:
        if (TextUtils.isEmpty(tvcertificateNo.getText().toString())) {
          Toast.makeText(getActivity(), R.string.noCertificateNo, Toast.LENGTH_SHORT).show();
          return true;
        }
        if (TextUtils.isEmpty(etoffBorrow.getText().toString()) || TextUtils.isEmpty(
            etpoutAmount.getText().toString()) || TextUtils.isEmpty(
            ettoutAmount.getText().toString())) {
          Toast.makeText(getActivity(), R.string.noTure, Toast.LENGTH_SHORT).show();
          return true;
        }
        if (TextUtils.isEmpty(tvappobjectName.getText().toString())) {
          Toast.makeText(getActivity(), R.string.noAppobjectName, Toast.LENGTH_SHORT).show();
          return true;
        }
        /**
         * 应报销    抵扣  实际报销  借款  有票  无票  预存票

         1. 抵扣的值<= 历史借款

         2. 无票的值 = 0

         3. 实际报销+抵扣的和 = 应报销

         4. 有票= 应报销

         5.本次预存票据费用=0；
         */
        //			Double sumPrebill=Double.parseDouble( tvsumPrebill.getText().toString());
        //合计>=冲抵
        Double sumBorrow = Double.parseDouble(tvsumBorrow.getText().toString());
        Double offBorrow = Double.parseDouble(etoffBorrow.getText().toString());
        double result = sumBorrow - offBorrow;

        LogUtil.i(offBorrow + "");
        //应支出金额 = 实际支出+抵扣借款
        Double toutAmount = Double.parseDouble(etpoutAmount.getText().toString());//应报销
        Double poutAmount = Double.parseDouble(ettoutAmount.getText().toString());//实际报销
        double result1 = 0;
        //如果选择冲抵  应支出金额 = 实际支出+抵扣借款
        if (TRUE.equals(tag)) {
          result1 = poutAmount + offBorrow;
          LogUtil.i("result1-----" + "result1 = poutAmount+offBorrow;");
        }
        //不选冲抵  应支出金额 = 实际支出
        else {
          result1 = poutAmount;
          LogUtil.i("result1-----" + "result1 = poutAmount");
        }

        //判断填写的数据关系
        if (result < 0) {
          Toast.makeText(getActivity(), R.string.nobig, Toast.LENGTH_SHORT).show();
        } else if (result >= 0 && toutAmount == result1) {
          /**
           * 修改添加附件
           */
          //判断有无附件
          if (TextUtils.isEmpty(mFilePath)) {
            //附件为空时
            volleyPostSave();
          } else {
            //附件不为空时，先上传附件，再保存数据
            //自动生成id
            id = UUID.randomUUID().toString();
            MyUtils.showDialogLoading(getActivity());
            volleyExtra();
          }
        } else {
          Toast.makeText(getActivity(), R.string.moneyFalse, Toast.LENGTH_SHORT).show();
        }

        //			if (TextUtils.isEmpty(tvcertificateNo.getText().toString())) {
        //				Toast.makeText(getActivity(),R.string.noCertificateNo, Toast.LENGTH_SHORT).show();
        //				return true;
        //			}
        //			if (TextUtils.isEmpty(etoffBorrow.getText().toString()) || TextUtils.isEmpty(etpoutAmount.getText().toString())
        //					|| TextUtils.isEmpty(ettoutAmount.getText().toString())) {
        //				Toast.makeText(getActivity(),R.string.noTure, Toast.LENGTH_SHORT).show();
        //				return true;
        //			}
        //			/**
        //			 * 应报销    抵扣  实际报销  借款  有票  无票  预存票
        //
        //				1. 抵扣的值<= 历史借款
        //
        //				2. 无票的值 <= 预存票
        //
        //				3. 实际报销+抵扣的和 <= 应报销
        //
        //				4. 有票+无票的和  >= 应报销
        //			 */
        //			Double sumPrebill=Double.parseDouble( tvsumPrebill.getText().toString());
        //			//合计>=冲抵
        //			Double sumBorrow=Double.parseDouble( tvsumBorrow.getText().toString());
        //			Double offBorrow=Double.parseDouble(etoffBorrow.getText().toString());
        //			double result = sumBorrow- offBorrow;
        //
        //			LogUtil.i(offBorrow+"");
        //			//应支出金额 >= 实际支出+抵扣借款
        //			Double toutAmount=Double.parseDouble( etpoutAmount.getText().toString());//应报销
        //			Double poutAmount=Double.parseDouble( ettoutAmount.getText().toString());//实际报销
        //			double result1 = poutAmount+offBorrow;
        //			//判断填写的数据关系
        //			if (result<0) {
        //				Toast.makeText(getActivity(),R.string.nobig, Toast.LENGTH_SHORT).show();
        //			}else if (result>=0 && toutAmount >= result1) {
        //
        //				if (!TextUtils.isEmpty(etnobillAmount.getText().toString()) ) {
        //					//2. 无票的值 <= 预存票
        //					Double nobillAmount=Double.parseDouble( etnobillAmount.getText().toString());
        //
        //					if (nobillAmount>sumPrebill) {
        //						Toast.makeText(getActivity(),"无票费用不能大于合计预存票据", Toast.LENGTH_SHORT).show();
        //					}else {
        //						if (!TextUtils.isEmpty(etbillAmount.getText().toString())) {
        //							Double billAmount=Double.parseDouble( etbillAmount.getText().toString());
        //							if (nobillAmount+billAmount < toutAmount) {
        //								Toast.makeText(getActivity(),"无票与有票的和不能小于应报销", Toast.LENGTH_SHORT).show();
        //							}else {
        ////							volleyPostSave();
        //								//选择新附件
        //								if (!TextUtils.isEmpty(mTvExtra.getText().toString()) && !TextUtils.isEmpty(mfileName) && !TextUtils.isEmpty(mDocPath)) {
        //									//上传新附件,首先将原始附件删除成功，再上传新附件
        //									volleyExtra();
        ////									volleyDelete();
        //								}
        //								//附件为空时
        //								else if (TextUtils.isEmpty(mTvExtra.getText().toString())&& TextUtils.isEmpty(mfileName) && TextUtils.isEmpty(mDocPath)) {
        //									selcurFile="";
        //									mfileName="";
        //									volleyPostSave();
        //									//本次预存票据费用=票据费用+无票费用-应报销费用
        //									replenishAmount=nobillAmount+billAmount-toutAmount;
        //									if (replenishAmount<0) {
        //										replenishAmount=0.00;
        //									}else {
        //										replenishAmount=nobillAmount+billAmount-toutAmount;
        //									}
        //
        //								}
        //								//附件没有修改时
        //								else {
        //									volleyPostSave();
        //									//本次预存票据费用=票据费用+无票费用-应报销费用
        //									replenishAmount=nobillAmount+billAmount-toutAmount;
        //									if (replenishAmount<0) {
        //										replenishAmount=0.00;
        //									}else {
        //										replenishAmount=nobillAmount+billAmount-toutAmount;
        //									}
        //								}
        //					       }
        //						}else {
        //							//有票费用为空时
        //							if (nobillAmount>=toutAmount) {
        ////								volleyPostSave();
        //
        //								//选择新附件，首先将原始附件删除成功，再上传新附件
        //								if (!TextUtils.isEmpty(mTvExtra.getText().toString()) && !TextUtils.isEmpty(mfileName) && !TextUtils.isEmpty(mDocPath)) {
        //									//上传新附件
        //									volleyExtra();
        ////									volleyDelete();
        //								}
        //								//附件为空时
        //								else if (TextUtils.isEmpty(mTvExtra.getText().toString())&& TextUtils.isEmpty(mfileName) && TextUtils.isEmpty(mDocPath)) {
        //									selcurFile="";
        //									mfileName="";
        //									volleyPostSave();
        //									//本次预存票据费用=票据费用+无票费用-应报销费用
        //									replenishAmount=nobillAmount-toutAmount;
        //									if (replenishAmount<0) {
        //										replenishAmount=0.00;
        //									}else {
        //										replenishAmount=nobillAmount-toutAmount;
        //									}
        //
        //								}
        //								//附件没有修改时
        //								else {
        //									volleyPostSave();
        //									//本次预存票据费用=票据费用+无票费用-应报销费用
        //									replenishAmount=nobillAmount-toutAmount;
        //									if (replenishAmount<0) {
        //										replenishAmount=0.00;
        //									}else {
        //										replenishAmount=nobillAmount-toutAmount;
        //									}
        //								}
        //							}else {
        //								Toast.makeText(getActivity(),R.string.falseMessage, Toast.LENGTH_SHORT).show();
        //							}
        //						}
        //
        //					}
        //				}else {
        //					if (!TextUtils.isEmpty(etbillAmount.getText().toString())) {
        //						Double billAmount=Double.parseDouble( etbillAmount.getText().toString());
        //						if (billAmount < toutAmount) {
        //							Toast.makeText(getActivity(),R.string.falseMessage, Toast.LENGTH_SHORT).show();
        //						}else {
        ////						volleyPostSave();
        //							//选择新附件
        //							if (!TextUtils.isEmpty(mTvExtra.getText().toString()) && !TextUtils.isEmpty(mfileName) && !TextUtils.isEmpty(mDocPath)) {
        //								//上传新附件，首先将原始附件删除成功，再上传新附件
        //								volleyExtra();
        ////								volleyDelete();
        //							}
        //							//附件为空时
        //							else if (TextUtils.isEmpty(mTvExtra.getText().toString())&& TextUtils.isEmpty(mfileName) && TextUtils.isEmpty(mDocPath)) {
        //								selcurFile="";
        //								mfileName="";
        //								volleyPostSave();
        //								//本次预存票据费用=票据费用+无票费用-应报销费用
        //								replenishAmount=billAmount-toutAmount;
        //								if (replenishAmount<0) {
        //									replenishAmount=0.00;
        //								}else {
        //									replenishAmount=billAmount-toutAmount;
        //								}
        //
        //							}
        //							//附件没有修改时
        //							else {
        //								volleyPostSave();
        //								//本次预存票据费用=票据费用+无票费用-应报销费用
        //								replenishAmount=billAmount-toutAmount;
        //								if (replenishAmount<0) {
        //									replenishAmount=0.00;
        //								}else {
        //									replenishAmount=billAmount-toutAmount;
        //								}
        //							}
        //				        }
        //
        //			         }else {
        //						//有票和无票都为空时
        //			        	 Toast.makeText(getActivity(),R.string.falseMessage, Toast.LENGTH_SHORT).show();
        //					}
        //
        //				}
        //			}else {
        //				Toast.makeText(getActivity(),R.string.falseMessage, Toast.LENGTH_SHORT).show();
        //			}

        return true;

      default:
        return super.onOptionsItemSelected(item);
    }
  }

  //删除附件
  private void volleyDelete() {
    String url = ApiConst.getAbsoluteUrl(ApiConst.URL_DELETE_FILE);
    HashMap<String, String> params = new HashMap<String, String>();
    params.put("selcurFile", selcurFile);
    mActivity.volleyPost(url, params, new VolleyResponse() {

      @Override public void onVolleyResponse(String arg0) {
        DeleteSuccessMessage result =
            new Gson().fromJson(new String(arg0), DeleteSuccessMessage.class);
        try {

          SuccessMessage delResult = new Gson().fromJson(new String(arg0), SuccessMessage.class);
          //删除成功
          if (delResult != null && delResult.getResult() != null && result.getResult()
              .equals("1")) {
            Toast.makeText(getActivity(), "删除成功", Toast.LENGTH_SHORT).show();
            volleyExtra();//上传新附件
          } else {
            Toast.makeText(getActivity(), "文件不存在", Toast.LENGTH_SHORT).show();
            volleyExtra();//上传新附件
          }
        } catch (JsonSyntaxException e) {
          e.printStackTrace();
          Toast.makeText(getActivity(), R.string.fileUploadFailure, Toast.LENGTH_SHORT).show();
        } catch (Resources.NotFoundException e) {
          e.printStackTrace();
          Toast.makeText(getActivity(), R.string.fileUploadFailure, Toast.LENGTH_SHORT).show();
        }
      }

      @Override public void onVolleyError(VolleyError arg0) {
        Toast.makeText(getActivity(), "删除失败", Toast.LENGTH_SHORT).show();
      }
    });
  }

  //附件上传方法
  private void volleyExtra() {

    new FileNetWorkUtil(getActivity()).upLoadFile(mFilePath, ApiConst.URL_UPLOAD_FILE,
        "r_expense_inexp_main", mContent.getId(), new myUpLoadHandler(), false);
  }

  private class myUpLoadHandler extends AsyncHttpResponseHandler {
    @Override public void onStart() {
      MyUtils.showDialogLoading(getActivity());
      super.onStart();
    }

    @Override public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {
      MyUtils.dismissDialog();
      Toast.makeText(getActivity(), R.string.fileUploadFailure, Toast.LENGTH_SHORT).show();
    }

    @Override public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
      //				MyUtils.dismissDialog();
      LogUtil.i("arg2==" + new String(arg2));
      try {

        SuccessMessage result = new Gson().fromJson(new String(arg2), SuccessMessage.class);
        if (result == null) {
          MyUtils.dismissDialog();
          Toast.makeText(getActivity(), R.string.wrong_data, Toast.LENGTH_SHORT).show();
        }
        if (result != null && result.getResult() != null && result.getResult().equals("1")) {
          //						Toast.makeText(getActivity(), R.string.fileUploadSuccess, Toast.LENGTH_SHORT).show();
          // 上传成功,再上传数据
          selcurFile = result.getMessage().toString();
          selcurFile = selcurFile.replace("\\", "/");
          LogUtil.i("selcurFile==" + selcurFile);
          //上传数据
          volleyPostSave();
        } else {
          MyUtils.dismissDialog();
          //						Toast.makeText(getActivity(), result.getMessage(), Toast.LENGTH_SHORT).show();
          //重命名，重新上传文件
          //						mDocPath=FileUtil.renameFile(mDocPath);
          //						mfileName=FileUtil.getFileNameByFilePath(mDocPath);
          //						LogUtil.i("重命名mFilePath==="+mDocPath);
          //						//刷新sd卡
          //						MediaScannerConnection.scanFile(getActivity(), new String[]{Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getPath()+"/"+mfileName}, null, null);
          //						new FileNetWorkUtil(getActivity()).upLoadFile(mDocPath, ApiConst.URL_UPLOAD_FILE, "r_expense_inexp_main",mContent.getId(), new myUpLoadHandler(), false);

          DialogFragment dialog = null;
          FragmentManager fm = getActivity().getSupportFragmentManager();
          dialog = BaseSingleButtonDialogFragment.newInstance(R.string.rename_file,
              R.string.restart_title);
          dialog.setTargetFragment(EditeManageReimburseFragment.this, REQUEST_RENAME);
          dialog.show(fm, "");
        }
      } catch (JsonSyntaxException e) {
        e.printStackTrace();
        Toast.makeText(getActivity(), R.string.fileUploadFailure, Toast.LENGTH_SHORT).show();
      } catch (Resources.NotFoundException e) {
        e.printStackTrace();
        Toast.makeText(getActivity(), R.string.fileUploadFailure, Toast.LENGTH_SHORT).show();
      }
    }
  }

  private void volleyPostSave() {

    String url = ApiConst.getAbsoluteUrl(ApiConst.URL_PESONAL_SAVE);

    HashMap<String, String> params = new HashMap<String, String>();
    mContent.setCertificateNo(tvcertificateNo.getText().toString());
    mContent.setSumBorrow(tvsumBorrow.getText().toString());
    mContent.setApplyTime(tvapplyTime.getText().toString());

    mContent.setExpenseDesc(etexpenseDesc.getText().toString());
    mContent.setPoutAmount(ettoutAmount.getText().toString());
    mContent.setOffBorrow(etoffBorrow.getText().toString());
    mContent.setToutAmount(etpoutAmount.getText().toString());
    mContent.setIfOffBorrow(tag);
    //票据
    //		mContent.setSumPrebill(tvsumPrebill.getText().toString());
    ////		mContent.setBillNo(etbillNo.getText().toString());
    //		mContent.setBillAmount(etbillAmount.getText().toString());
    //		mContent.setNobillAmount(etnobillAmount.getText().toString());
    //		mContent.setReplenishAmount(replenishAmount.toString());

    //        mContent.setBillAmount(etbillAmount.getText().toString());
    //        mContent.setDeductionAmount(etdeductionAmount.getText().toString());

    //		mContent.setSumPrebill(mContent.getSumPrebill());
    //		mContent.setNobillAmount("0");
    //		mContent.setReplenishAmount("0");

    mContent.setPayeeBank(etpayeeBank.getText().toString());
    mContent.setPayeeAccname(etpayeeAccname.getText().toString());
    mContent.setPayeeAccount(etpayeeAccount.getText().toString());

    // 合同
    if (!TextUtils.isEmpty(tvcontractId.getText().toString())) {
      mContent.setContractId(mContractId);
      mContent.setContractName(mContractName);
      mContent.setContractKind(mContractKind);
      mContent.setContractCode(mContractCode);
      mContent.setOrderId(mOrderId);
      mContent.setOrderName(mOrderName);
      mContent.setOrderType(mOrderType);
      mContent.setContractProjectId(mProjectId);
      mContent.setContractProjectName(mProjectName);
      if (mContractPrice == null || TextUtils.isEmpty(mContractPrice) || "null".equals(
          mContractPrice)) {
        mContent.setContractAmount("0");
      } else {
        mContent.setContractAmount(mContractPrice);
      }
    }
    //		if (!TextUtils.isEmpty(selcurFile)) {
    //附件
    mContent.setFileOriginalName(mfileName);
    mContent.setFilePath(selcurFile);
    //		}

    mContent.setFownerkindName(fownerkindName);
    mContent.setFownerkindCode(fownerkindCode);
    mContent.setAppobjectName(appobjectName);
    mContent.setAppobjectId(appobjectCode);
    params.put("json", new Gson().toJson(mContent).toString());
    params.put("memberCode", mCurrentUser.getMemberCode());
    params.put("certificateCode", mContent.getCertificateCode());
    params.put("regJobNo", mCurrentUser.getJobNumber());
    params.put("type", "mobile");
    LogUtil.i("修改合同参数===" + params.toString());
    MyUtils.showDialogLoading(getActivity());
    mActivity.volleyPost(url, params, new VolleyResponse() {

      @Override public void onVolleyResponse(String arg0) throws JSONException {
        SuccessMessage[] result = new Gson().fromJson(arg0, SuccessMessage[].class);
        SuccessMessage workProcess = result[0];
        if (null == workProcess || null == workProcess.getResult()) {
          Toast.makeText(getActivity(), R.string.failure_operation, Toast.LENGTH_SHORT).show();
          return;
        }
        String successType = workProcess.getResult();
        if (successType.equals(SuccessMessage.FAILURE)) {
          Toast.makeText(getActivity(), R.string.failure_operation, Toast.LENGTH_SHORT).show();
          return;
        }
        if (successType.equals(SuccessMessage.SUCCESS)) {
          Toast.makeText(getActivity(), R.string.success_operation, Toast.LENGTH_SHORT).show();
          getActivity().setResult(Activity.RESULT_OK);

          getActivity().finish();
        }
      }

      @Override public void onVolleyError(VolleyError arg0) {
        // Auto-generated method stub

      }
    });
  }

  @Override public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != Activity.RESULT_OK) {
      return;
    }
    if (requestCode == REQUEST_RENAME) {

      return;
    }

    super.onActivityResult(requestCode, resultCode, data);
  }

  // fragment之间传值
  public static EditeManageReimburseFragment newInstance(EmployeeLoanContent item) {
    Bundle args = new Bundle();
    args.putSerializable(EXTRA_TRAVELREIMBURSE_CONTENT, item);
    EditeManageReimburseFragment fragment = new EditeManageReimburseFragment();
    fragment.setArguments(args);
    return fragment;
  }
}
